Skip to main content
This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal

Notes/Domino 6 and 7 Forum

Notes/Domino 6 and 7 Forum


  

PreviousPrevious NextNext


~Keiko Preponeterader 21.Jul.03 09:17 PM a Web browser
Applications Development All Releases Windows 2000; Windows XP


Ever needed to print something in LotusScript to a printer other than the current default printer? Ever needed to let the user select that printer on the fly? The script below will do this for Windows 2000 machines and, I presume Windows XP (I've only tried it on 2000).

Declare Function GetProfileString Lib "kernel32" Alias "GetProfileStringA" (Byval lpAppName As String, Byval lpKeyName As String, Byval lpDefault As String, Byval lpReturnedString As String, Byval nSize As Long) As Long

Sub [whatever]
Dim WshNetwork As Variant
Dim WshPrinters As Variant
Dim pArray() As String
Dim strBuffer As String * 254
Dim iRetValue As Long
Dim DefaultPrinter As String
Dim pCount As Integer
Dim n As Integer
Dim PrinterPath As Variant

' Retreive current default printer information
iRetValue = GetProfileString("windows", "device", ",,,", strBuffer, 254)
DefaultPrinter$ = Left(strBuffer, Instr(strBuffer, ",") - 1)
Print "Current default printer is " & DefaultPrinter$

Set WshNetwork = CreateObject("WScript.Network")
Set WshPrinters = WshNetwork.EnumPrinterConnections()

'count the connected printers
pCount% = 0
For n = 1 To WshPrinters.Count() Step 2
If wshPrinters(n) <> "" Then pCount%=pCount%+1
Next

'collect the names of the connected printers
Redim pArray(pCount%-1) As String
pCount% = 0
For n = 1 To WshPrinters.Count() Step 2
If wshPrinters(n) <> "" Then
pArray(pCount%) = wshPrinters(n)
pCount%=pCount%+1
End If
Next

PrinterPath = ws.Prompt(4,"Select Printer","Choose a printer from the following list:","",pArray)
If Cstr(PrinterPath)="" Then Exit Sub

WshNetwork.SetDefaultPrinter Cstr(PrinterPath)

Print "Default printer is now " & Cstr(PrinterPath)

'*****************************************
' Print what you need to print here
'*****************************************

WshNetwork.SetDefaultPrinter DefaultPrinter$
Print "Default printer restored to " & DefaultPrinter$

Set WshNetwork = Nothing
Set WshPrinters = Nothing
End Sub






Script for Setting & Resetting the ... (~Keiko Preponet... 21.Jul.03)
. . RE: Script for Setting & Resetting ... (~Sarah Opnuplop... 24.Jul.03)
. . . . RE: Script for Setting & Resetting ... (~Keiko Preponet... 28.Jul.03)





  Document options
Print this pagePrint this page

 Search this forum

  Forum views and search
Date (threaded)
Date (flat)
With excerpt
Category
Platform
Release
Advanced search

 RSS feedsRSS
All forum posts RSS
All main topics RSS